package com.feign.controller;

import com.feign.service.EnterpriseClientService;
import com.feign.service.SsoClientService;
import com.feign.util.SSOUtil;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by yangjianbo on 2016/10/19.
 */
//@Controller
public class SsoController {

    @Autowired
    private SsoClientService ssoClientService;

    @RequestMapping(method = RequestMethod.POST, value = "sso/login")
    @ResponseBody
    String login(@RequestParam String username,
                 @RequestParam  String password){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String client_agent = request.getHeader("user-agent");//获取浏览器信息
        String referer_uri=request.getHeader("Referer");
        String client_ip=SSOUtil.getIpAddr(request);
       return ssoClientService.login(username,password,client_agent,client_ip,referer_uri);
    }

    @RequestMapping(method = RequestMethod.POST, value = "sso/get")
    @ResponseBody
    String get(@RequestParam String clientIp,
                 @RequestParam  String clientAgent){
        return ssoClientService.get(clientAgent,clientIp);
    }

    @RequestMapping(method = RequestMethod.POST, value = "sso/out")
    @ResponseBody
    String out(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String client_agent = request.getHeader("user-agent");//获取浏览器信息
        String client_ip=SSOUtil.getIpAddr(request);
        return ssoClientService.out(client_ip,client_agent);
    }

}
